#include <stdarg.h>
#include <stdio.h>
#include <memory.h>
#include "systemLogger.h"

uint8 SystemLogger::m_iLevel = LOG_LEVEL_INFO;

SystemLogger::SystemLogger()
{
	
}

SystemLogger::~SystemLogger()
{
	
}

void SystemLogger::SetLevel(uint8 iLevel)
{
	m_iLevel = iLevel;
}

void SystemLogger::LogDebug(const char* szFormatString, ...)
{
	if (m_iLevel < LOG_LEVEL_DEBUG)
		return;
	
	char szMessage[MAX_LINE_LENGTH + 1];
	memset(szMessage, 0, MAX_LINE_LENGTH + 1);
	
	uint32 iOffset = 0;
	va_list pArguments;
	va_start(pArguments, szFormatString);
	vsnprintf(szMessage + iOffset, MAX_LINE_LENGTH - iOffset, szFormatString, pArguments);
	va_end(pArguments);
	
	Log(szMessage);
}

void SystemLogger::LogInfo(const char* szFormatString, ...)
{
	if (m_iLevel < LOG_LEVEL_INFO)
		return;
	
	char szMessage[MAX_LINE_LENGTH + 1];
	memset(szMessage, 0, MAX_LINE_LENGTH + 1);
	
	uint32 iOffset = 0;
	va_list pArguments;
	va_start(pArguments, szFormatString);
	vsnprintf(szMessage + iOffset, MAX_LINE_LENGTH - iOffset, szFormatString, pArguments);
	va_end(pArguments);
	
	Log(szMessage);
}

void SystemLogger::LogWarn(const char* szFormatString, ...)
{
	if (m_iLevel < LOG_LEVEL_WARN)
		return;
	
	char szMessage[MAX_LINE_LENGTH + 1];
	memset(szMessage, 0, MAX_LINE_LENGTH + 1);
	
	uint32 iOffset = 0;
	va_list pArguments;
	va_start(pArguments, szFormatString);
	vsnprintf(szMessage + iOffset, MAX_LINE_LENGTH - iOffset, szFormatString, pArguments);
	va_end(pArguments);
	
	Log(szMessage);
}

void SystemLogger::LogError(const char* szFormatString, ...)
{
	if (m_iLevel < LOG_LEVEL_ERROR)
		return;
	
	char szMessage[MAX_LINE_LENGTH + 1];
	memset(szMessage, 0, MAX_LINE_LENGTH + 1);
	
	uint32 iOffset = 0;
	va_list pArguments;
	va_start(pArguments, szFormatString);
	vsnprintf(szMessage + iOffset, MAX_LINE_LENGTH - iOffset, szFormatString, pArguments);
	va_end(pArguments);
	
	Log(szMessage);
}
